from appium import webdriver
from time import sleep
import subprocess

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

desired_caps = {
    "platformName": "Android",
    "automationName": "uiautomator2",
    "platformVersion": "9",
    "deviceName": '2023052000001415',
    "appPackage": "com.seven.qaml.burstserven",
    "appActivity": "com.seven.qaml.burstserven.ui.MenuActivity",
    'skipServerInstallation': False,
    'skipDeviceInitialization': False,
    "noReset": True
}
appium_server_url = 'http://127.0.0.1:4723'
driver = webdriver.Remote(appium_server_url, desired_caps)
#
# subprocess.run('adb shell am start -n com.seven.qaml.burstserven/.ui.LoginActivity', shell=True,
#                capture_output=True, text=True)
#
# login = WebDriverWait(driver, 10).until(
#     EC.element_to_be_clickable((By.ID, 'com.seven.qaml.burstserven:id/btn_info')))
# login.click()
# driver.keyevent(66)
#
# while True:
#     if driver.find_elements('id', 'com.seven.qaml.burstserven:id/text_ver'):
#         driver.keyevent(66)
#         break

sleep(5)
count = 1

while count < 64:
    driver.keyevent(11)
    sleep(15)
    driver.keyevent(4)
    # driver.keyevent(21)
    # driver.keyevent(66)
    driver.find_element('id', 'com.seven.qaml.burstserven:id/button1').click()
    sleep(10)

    print(f"already executed {count} times")
    count += 1
